import akshare as ak
from connector import mysqlConnectorHelper as mc
import datetime
import SimpleMySqlClass as smc


# 获取数据库链接
def get_mysql_conn():
    conn = smc.SimpleMySqlClass("127.0.0.1", "stocks", "haojg", "haojg")
    return conn


def get_data_and_read(code):
    # 获取链接
    conn = get_mysql_conn()

    # 读数
    read_data_from_mysql(conn)
    # 关闭连接
    conn.close()


# 3, query data from mysql
def read_data_from_mysql(conn):
    tableName = "t_stock_k_data"
    # sql = f"select sd_date, sd_code, sd_open, sd_high, sd_low, sd_close, sd_volume, sd_amount from {tableName}"
    sql = f"select sd_date as date, sd_code as code, sd_open as code, sd_high as high, sd_low as low, sd_close as low, sd_volume as volume, sd_amount as amount from {tableName}"
    rs = conn.get_all(sql)
    print("query rs = ", rs)
    pass


if __name__ == "__main__":
    code = "002202"
    get_data_and_read(code)
    print("main")
